package com.eascs.banknet.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class DateUtil {
   
	/**
	 * 获取前n天日期字符串
	 * @param beginDate
	 * @param num
	 * @return
	 * @throws Exception
	 */
   public static List<String> getDateList(Date beginDate, int n) throws Exception{
	   List<String> dateList = new LinkedList<String>();
	   for(int i = 1; i <= n; i++){
			SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
			Calendar date = Calendar.getInstance();
			date.setTime(beginDate);
			date.set(Calendar.DATE, date.get(Calendar.DATE) - i);
			Date endDate = dft.parse(dft.format(date.getTime()));
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			dateList.add(sdf.format(endDate));
			
	   }
	   return dateList;
   }
}
